package view;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.DefaultListModel;

/**
 * Vista del frame principal del proyecto
 * @author Samuel Chávez, Axel Mayorga
 */
public class ChessboardView extends javax.swing.JFrame {

    /** Creates new form ChessboardView */
    public ChessboardView() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jDialog2 = new javax.swing.JDialog();
        jFrame1 = new javax.swing.JFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        lst_CodeProlog = new javax.swing.JList();
        btn_Solve = new javax.swing.JButton();
        btn_Reset = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btn_PrevSolution = new javax.swing.JButton();
        btn_NextSolution = new javax.swing.JButton();
        pan_Chessboard = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mnu_EditChessboard = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        mnu_Solve = new javax.swing.JMenuItem();
        mnu_PrevSolution = new javax.swing.JMenuItem();
        mnu_NextSolution = new javax.swing.JMenuItem();

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jDialog2Layout = new javax.swing.GroupLayout(jDialog2.getContentPane());
        jDialog2.getContentPane().setLayout(jDialog2Layout);
        jDialog2Layout.setHorizontalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog2Layout.setVerticalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lst_CodeProlog.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "asdf", "asdf" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(lst_CodeProlog);

        btn_Solve.setText("Resolve");

        btn_Reset.setText("Reset board");

        jLabel1.setText("Action log:");

        btn_PrevSolution.setText("Previous Solution");

        btn_NextSolution.setText("Next Solution");

        pan_Chessboard.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout pan_ChessboardLayout = new javax.swing.GroupLayout(pan_Chessboard);
        pan_Chessboard.setLayout(pan_ChessboardLayout);
        pan_ChessboardLayout.setHorizontalGroup(
            pan_ChessboardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 632, Short.MAX_VALUE)
        );
        pan_ChessboardLayout.setVerticalGroup(
            pan_ChessboardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 565, Short.MAX_VALUE)
        );

        jMenu1.setText("Puzzle");

        mnu_EditChessboard.setText("Edit chessboard");
        jMenu1.add(mnu_EditChessboard);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Run");

        mnu_Solve.setText("Solve");
        jMenu2.add(mnu_Solve);

        mnu_PrevSolution.setText("Previous solution");
        jMenu2.add(mnu_PrevSolution);

        mnu_NextSolution.setText("Next solution");
        jMenu2.add(mnu_NextSolution);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pan_Chessboard, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btn_PrevSolution)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_NextSolution, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btn_Solve, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pan_Chessboard, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_Solve, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btn_NextSolution, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btn_PrevSolution, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_NextSolution;
    private javax.swing.JButton btn_PrevSolution;
    private javax.swing.JButton btn_Reset;
    private javax.swing.JButton btn_Solve;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JDialog jDialog2;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList lst_CodeProlog;
    private javax.swing.JMenuItem mnu_EditChessboard;
    private javax.swing.JMenuItem mnu_NextSolution;
    private javax.swing.JMenuItem mnu_PrevSolution;
    private javax.swing.JMenuItem mnu_Solve;
    private javax.swing.JPanel pan_Chessboard;
    // End of variables declaration//GEN-END:variables

    // MVC Comunmication
    public void addEditChessboardListener(ActionListener al)
    {
        mnu_EditChessboard.addActionListener(al);
    }
    
    public void addResetChessboardListener(ActionListener al)
    {
        btn_Reset.addActionListener(al);
    }
    
    public void addSolveListener(ActionListener al)
    {
        mnu_Solve.addActionListener(al);
        btn_Solve.addActionListener(al);
    }
    
    public void addPreviousSolutionListener(ActionListener al)
    {
        mnu_PrevSolution.addActionListener(al);
        btn_PrevSolution.addActionListener(al);
    }
        
    public void addNextSolutionListener(ActionListener al)
    {
        mnu_NextSolution.addActionListener(al);
        btn_NextSolution.addActionListener(al);
    }
    
    public void setListCodePrologModel(DefaultListModel  model)
    {
        lst_CodeProlog.setModel(model);
    }
    
    public void addToChessboard(Component cmp)
    {
        pan_Chessboard.add(cmp);
        pan_Chessboard.repaint();
    }
    
    public void cleanChessBoard()
    {
        pan_Chessboard.removeAll();
    }
    
    public int getChessboardHeight()
    {
        return pan_Chessboard.getHeight();
    }
    
    public int getChessboardWidth()
    {
        return pan_Chessboard.getWidth();
    }
    
    public void setEnabledPrevSolution(boolean enabled)
    {
        btn_PrevSolution.setEnabled(enabled);
    }
    
    public void setEnabledNextSolution(boolean enabled)
    {
        btn_NextSolution.setEnabled(enabled);
    }
    //End MVC Comumnication
}
